using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace DeviceAndSensor;

[ObservableObject]
public partial class MainPageViewModel {
    [ObservableProperty] private string _model = DeviceInfo.Current.Model;

    [ObservableProperty]
    private string _manufacturer = DeviceInfo.Current.Manufacturer;

    [ObservableProperty] private string _name = DeviceInfo.Current.Name;

    [ObservableProperty]
    private string _version = DeviceInfo.Current.VersionString;

    [ObservableProperty]
    private string _platform = DeviceInfo.Current.Platform.ToString();

    [ObservableProperty] private string _location;

    [RelayCommand]
    private async Task GetLocation() {
        var request = new GeolocationRequest(GeolocationAccuracy.Best,
            TimeSpan.FromSeconds(60));
        var location = await Geolocation.Default.GetLocationAsync(request);

        if (location is null) {
            return;
        }

        Location = $"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}";
    }
}